/**
 * FileName: MyFactoryBean
 * Author:   xing.yang@vcg.com
 * Date:     2020/6/2 17:37
 * Description:
 */
package com.vcg.vdam.config;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;

public class MyFactoryBean implements FactoryBean ,InitializingBean {

    private Class tClass;

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Class gettClass() {
        return tClass;
    }

    public void settClass(Class tClass) {
        this.tClass = tClass;
    }

    @Nullable
    @Override
    public Object getObject() throws Exception {
        Object object = null;
        if(tClass == TestBean4.class){
            TestBean4 testBean4 = new TestBean4();
            testBean4.setName("我是facotorybean创建的test4");
            object =testBean4;
        }else if(tClass == TestBean5.class){
            TestBean5 testBean5 = new TestBean5();
            testBean5.setName("我是facotorybean创建的test5");
            object = testBean5;
        }

        return object;
    }

    @Nullable
    @Override
    public Class<?> getObjectType() {
        return tClass;
    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }
}
